package com.lzx.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lzx.api.CommonResult;
import com.lzx.entity.Brand;
import com.lzx.entity.Pictrue;
import com.lzx.entity.Product;
import com.lzx.service.BrandService;
import com.lzx.service.CategoryService;
import com.lzx.service.PictrueService;
import com.lzx.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: lzx
 * @Date: 2021/3/8 10:34
 */
@RestController
@RequestMapping("/home")
public class HomeController {
    @Autowired
    private PictrueService pictrueService;
    @Autowired
    private ProductService productService;
    @Autowired
    private BrandService brandService;
    @Autowired
    private CategoryService categoryService;
    /**
     * 获取轮播图
     * @return
     */
    @GetMapping("/carousel")
    public CommonResult getCarousel(){
        List<Pictrue> carouselList = pictrueService.list(new QueryWrapper<Pictrue>().eq("type", "carousel"));
        return CommonResult.success(carouselList);
    }
    @GetMapping("/getRecommend")
    public CommonResult getRecommend(@RequestParam String categoryName){
        List recommendList = null;
        switch (categoryName){
            case "商品":
                recommendList =  productService.getRecommend();
                break;
            case "品牌":
                recommendList = brandService.getRecommend();
                break;
            case "分类":
                recommendList = categoryService.getRecommend();
                break;
            default:
        }

        return CommonResult.success(recommendList);
    }
}
